// pages/find/correct/detail/index.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    mask_images:false,//图册信息的滑块内容
    mast_image_index:0,//展示图片第几个开始

    mask_lifelogs:false,//生命流程弹窗是否展示
    mask_lifelogs_list:[],//生命流程内容列表

    mask_needmore_time:false,//需要更多时间的弹窗信息

    date:app.kuoqi.getDatestring(),
    datenow:app.kuoqi.getDatestring(),
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    app.kuoqi.initPage(this);//基础的数据初始化
    this.setData(options);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getDetail();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  
  //获取整改计划的详情
  getDetail:function(){
    //根据no获取详细信息
    var ths = this;
    var no = this.data.no;
    app.kuoqi.ajax({
      url:'/Api/Correct/Detail',
      data:{no:no},
      success:function(rs){
        if(rs.status==1){
          ths.setData({info:rs.data});
        }else{
          wx.showModal({
            title:'错误提示',
            content:rs.message,
            cancelColor: 'cancelColor',
          })
        }
      },
    });
  },

  //操作者提交审核
  doSubmitReview:function(){
    var ths = this;
    wx.showModal({
      title:'提交审核确认',
      content:'是否确认提交给部门负责人进行审核，审核通过之后将开始进行',
      cancelColor: 'cancelColor',
      success:function(rs){
        if(!rs.confirm){ return;}
        app.kuoqi.ajax({
          url:'/Api/Correct/SubmitReview',
          type:'post',
          dataType:'json',
          data:{
            no:ths.data.info.order_no
          },
          success:function(rs){
            if(rs.status==1){
              //提交审核成功，等待部门负责人审核
              wx.showModal({
                cancelColor: 'cancelColor',
                content:"提交审核成功，等待部门负责人审核",
                success:function(){
                  wx.redirectTo({
                    url: '/pages/find/correct/detail/index?no='+ths.data.info.order_no,
                  })
                },
              })
            }else{
              wx.showModal({
                cancelColor: 'cancelColor',
                content:rs.message,
              })
            }
          },
          error:function(){
            wx.showModal({
              content:"提交审核失败",
              cancelColor: 'cancelColor',
            })
          }
        });
      }
    })
  },

  //部门负责人审核不通过
  doDisagree:function(){
    var ths = this;
    //审核不通过，并用一个窗口进行消息回复的那种
    wx.showModal({
      cancelColor: 'cancelColor',
      editable:true,
      placeholderText:'请填写审核拒绝的理由',
      cancelText:'再想想',
      confirmText:'不通过',
      success:function(rs){
        if(!rs.confirm){ return;}
        app.kuoqi.ajax({
          url:'/Api/Correct/SubmitDisagree',
          type:'post',
          dataType:'json',
          data:{
            no:ths.data.info.order_no,
            remark:rs.content,
          },
          success:function(rs){
            if(rs.status==1){
              //审核成功之后刷新页面信息
              wx.redirectTo({
                url: '/pages/find/correct/detail/index?no='+ths.data.info.order_no,
              })
            }else{
              wx.showModal({
                cancelColor: 'cancelColor',
                content:rs.message,
              })
            }
          },
        });
      },
    })
  },

  /**
   * 审核通过
   */
  doAgree:function(){
    var ths = this;
    wx.showModal({
      cancelColor: 'cancelColor',
      content:'确定审核通过吗？',
      cancelText:'再想想',
      confirmText:'审核通过',
      success:function(rs){
        if(!rs.confirm){ return;}
        app.kuoqi.ajax({
          url:'/Api/Correct/SubmitAgree',
          type:'post',
          dataType:'json',
          data:{
            no:ths.data.info.order_no
          },
          success:function(rs){
            if(rs.status==1){
              //审核成功之后刷新页面信息
              wx.redirectTo({
                url: '/pages/find/correct/detail/index?no='+ths.data.info.order_no,
              })
            }else{
              wx.showModal({
                cancelColor: 'cancelColor',
                content:rs.message,
              })
            }
          },
        });
      },
    })
  },

  //审核通过之后开始整改的按钮提交
  doStartCorrect:function(e){
    var ths = this;
    wx.showModal({
      cancelColor: 'cancelColor',
      content:'确定开始整改吗？',
      cancelText:'再想想',
      confirmText:'确定',
      success:function(rs){
        if(!rs.confirm){ return;}
        app.kuoqi.ajax({
          url:'/Api/Correct/StartCorrect',
          type:'post',
          dataType:'json',
          data:{
            no:ths.data.info.order_no
          },
          success:function(rs){
            if(rs.status==1){
              //审核成功之后刷新页面信息
              wx.redirectTo({
                url: '/pages/find/correct/detail/index?no='+ths.data.info.order_no,
              })
            }else{
              wx.showModal({
                cancelColor: 'cancelColor',
                content:rs.message,
              })
            }
          },
        });
      },
    })
  },

  //整改完成提交，部门负责人审核的部分，这个因为需要进行一个拍照所以跳转页面
  doEndCorrect:function(){
    var no = this.data.info.order_no;
    wx.navigateTo({
      url: '/pages/find/correct/corsubmit/index?no='+no,
    })
  },

  //worker整改完成，提交部门负责人审核
  doEndCorrectbak:function(e){
    var ths = this;
    wx.showModal({
      cancelColor: 'cancelColor',
      content:'确认提交整改结果吗？',
      cancelText:'再想想',
      confirmText:'确定',
      success:function(rs){
        if(!rs.confirm){ return;}
        app.kuoqi.ajax({
          url:'/Api/Correct/EndCorrect',
          type:'post',
          dataType:'json',
          data:{
            no:ths.data.info.order_no
          },
          success:function(rs){
            if(rs.status==1){
              //审核成功之后刷新页面信息
              wx.showModal({
                content:rs.message,
                confirmText:'知道了',
                showCancel:false,
                success:function(){
                  wx.redirectTo({
                    url: '/pages/find/correct/detail/index?no='+ths.data.info.order_no,
                  })
                },
              })
            }else{
              wx.showModal({
                cancelColor: 'cancelColor',
                content:rs.message,
              })
            }
          },
        });
      },
    })
  },

  /**
   * 负责人审核整改结果信息，并同意
   */
  doFinishAgree:function(){
    var ths = this;
    wx.showModal({
      cancelColor: 'cancelColor',
      content:'确定审核通过吗？',
      cancelText:'再想想',
      confirmText:'通过',
      success:function(rs){
        if(!rs.confirm){ return;}
        app.kuoqi.ajax({
          url:'/Api/Correct/FinishAgree',
          type:'post',
          dataType:'json',
          data:{
            no:ths.data.info.order_no
          },
          success:function(rs){
            if(rs.status==1){
              //审核成功之后刷新页面信息
              wx.redirectTo({
                url: '/pages/find/correct/detail/index?no='+ths.data.info.order_no,
              })
            }else{
              wx.showModal({
                cancelColor: 'cancelColor',
                content:rs.message,
              })
            }
          },
        });
      },
    })
  },

  //showImages
  //展示图片合集信息
  showImages:function(e){
    this.setData({mask_images:true,mast_image_index:e.target.dataset.index})
  },
  showResultImages:function(e){
    this.setData({mask_result_images:true,mast_image_index:e.target.dataset.index})
  },

  bindDateChange:function(e){
    this.setData({
      date:e.detail.value,
    });
  },

  //同意延期到新的时间
  doAgreeMoretime:function(){
    var ths = this;
    var correct_no = this.data.info.order_no;
    wx.showModal({
      content:'是否同意延期？',
      cancelColor: 'cancelColor',
      confirmText:"同意",
      cancelText:"再想想",
      complete:function(rs){
        if(rs.confirm==false){
          return false;
        }
        app.kuoqi.ajax({
          url:'/Api/Correct/AgreeMoretime',
          dataType:'json',
          type:'post',
          data:{
            correct_no:correct_no
          },
          success:function(rs){
            if(rs.status==1){
              wx.showModal({
                content:rs.message,
                showCancel:false,
                cancelColor: 'cancelColor',
                success:function(){
                  wx.redirectTo({
                    url: '/pages/find/correct/detail/index?no='+correct_no,
                  })
                },
              })
            }else{
              wx.showModal({
                content:rs.message,
                showCancel:false,
                cancelColor: 'cancelColor',
              })
            }
          },
        });
      },
    })
  },
  
  doWarning:function(){
    wx.showModal({
      content:"延期太久会进入专项会，请尽快处理",
      showCancel:false,
      cancelColor: 'cancelColor',
    })
  },
})